package com.suneast.suneaststore.modules.search;

import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.util.DiffUtil;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.suneast.suneaststore.R;
import com.suneast.suneaststore.app.Latte;
import com.suneast.suneaststore.modules.goodsdetail.GoodsDetailFragment;
import com.suneast.suneaststore.bean.search.SearchBean;
import com.suneast.suneaststore.bean.search.SearchFilterBean;
import com.suneast.suneaststore.bean.search.SearchFilterItemBean;
import com.suneast.suneaststore.modules.search.adapter.SearchBeanAdapter;
import com.suneast.suneaststore.modules.search.adapter.SearchFilterAdapter;
import com.suneast.suneaststore.modules.search.event.FilterGotEvent;
import com.suneast.suneaststore.modules.search.event.ItemFilterCheckChangeEvent;
import com.suneast.suneaststore.modules.search.event.SearchPageEvent;
import com.suneast.suneaststore.modules.search.event.SearchResultEvent;
import com.suneast.suneaststore.ui.fragments.BaseFragment;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.WeakHashMap;

import butterknife.BindView;
import butterknife.BindViews;
import butterknife.OnClick;

/**
 * Created by zestz on 2018/3/31.
 */

public final class SearchFragment extends BaseFragment implements View.OnClickListener, BaseQuickAdapter.OnItemClickListener, OnLoadMoreListener, TextWatcher, BaseQuickAdapter.OnItemChildClickListener {

    @Override
    public @LayoutRes
    int setLayout() {
        return R.layout.fragment_search;
    }

    public final static String PAGE = "page";
    public final static String PSIZE = "psize";
    public final static String TYPE = "type";
    public final static String CATE = "cate";
    public final static String KEY_WORDS = "keywords";
    public final static String FILTERS = "filters";
    public final static String MERCH_ID = "merchid";
    public final static String BRAND = "brand";
    public final static String SORT = "sort";
    public final static String ORDER = "order";
    public final static String MAX_PRICE = "maxprice";
    public final static String MIN_PRICE = "minprice";

    public interface order {
        String id = "id";
        String createTime = "createtime";
        String comment = "comment";
        String salesReal = "salesreal";
        String memberPrice = "memberprice";

    }

    public interface sort {
        String desc = "desc";//从高到低
        String asc = "asc";//从低到高
    }

    @OnClick({R.id.layout_navigation_bar,
            R.id.tv_synthesize,
            R.id.tv_sales,
            R.id.tv_price,
            R.id.tv_filter,
            R.id.img_edit_delete,
            R.id.btn_search
    })
    public void onViewClick(View view) {
        switch (view.getId()) {
            case R.id.img_edit_delete: {
                keyWordEditText.setText("");
            }
            break;
            case R.id.btn_search: {
                //发起关键字搜索
                resetPage();
                paramsMap.put(KEY_WORDS, keyWordEditText.getText().toString());
                handleRequest(paramsMap);
                hideSoftInput();
            }
            break;
            case R.id.layout_navigation_bar: {
                synthesizeMenu.dismiss();
                priceMenu.dismiss();
                filterMenu.dismiss();
            }
            break;
            case R.id.tv_synthesize: {
                setTextState(0);
                if (priceMenu.isShowing()) {
                    priceMenu.dismiss();
                }
                if (synthesizeMenu.isShowing()) {
                    synthesizeMenu.dismiss();
                } else {
                    synthesizeMenu.showAsDropDown(layoutFilters);
                }
            }
            break;
            case R.id.tv_sales: {
                setTextState(1);
                if (priceMenu.isShowing()) {
                    priceMenu.dismiss();
                }
                if (synthesizeMenu.isShowing()) {
                    synthesizeMenu.dismiss();
                }
                Latte.getHandler().removeCallbacks(salesSortRun);
                Latte.getHandler().postDelayed(salesSortRun, 100);
                synthesizeMenu.dismiss();
                resetText(3);
            }
            break;
            case R.id.tv_price: {
                setTextState(2);
                if (synthesizeMenu.isShowing()) {
                    synthesizeMenu.dismiss();
                }
                if (priceMenu.isShowing()) {
                    priceMenu.dismiss();
                } else {
                    priceMenu.showAsDropDown(layoutFilters);
                }
            }
            break;
            case R.id.tv_filter: {
                setTextState(3);
                if (priceMenu.isShowing()) {
                    priceMenu.dismiss();
                }
                if (synthesizeMenu.isShowing()) {
                    synthesizeMenu.dismiss();
                }
                filterMenu.showAsDropDown(navigationLayout);
                if (simpleFilterList == null || simpleFilterList.size() == 0) {
                    SearchRequestHandler.requestFilters(cate, "");
                }
            }
            break;
        }
    }

    @BindView(R.id.layout_navigation_bar)
    Toolbar navigationLayout;

    @BindView(R.id.edit_text_key_word)
    EditText keyWordEditText;

    @BindView(R.id.img_edit_delete)
    ImageView editDeleteImg;

    @BindView(R.id.layout_filters)
    LinearLayout layoutFilters;

    @BindView(R.id.tv_synthesize)
    TextView synthesizeTv;

    @BindView(R.id.tv_price)
    TextView priceTv;

    @BindViews({R.id.tv_synthesize, R.id.tv_sales, R.id.tv_price, R.id.tv_filter})
    TextView[] filterTvs;

    @BindViews({R.id.img_synthesize, R.id.img_price, R.id.img_filter})
    ImageView[] imgVs;

    @BindView(R.id.refresh_layout_search)
    SmartRefreshLayout refreshLayout;
    private Runnable loadMoreRun;
    private Runnable salesSortRun;

    @BindView(R.id.rv_search)
    RecyclerView searchRV;
    private SearchBeanAdapter adapter;

    private int cate;
    private int curPage = 1;
    private boolean isLast;
    private WeakHashMap<String, Object> paramsMap;
    private ArrayList<String> filtersList;
    private ArrayList<SearchFilterBean> allFilterList;
    private ArrayList<SearchFilterBean> simpleFilterList;

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
        EventBus.getDefault().register(this);
        initView(rootView);
        allFilterList = new ArrayList<>();
        filtersList = new ArrayList<>();
        paramsMap = new WeakHashMap<>();
        paramsMap.put(PAGE, 1);
        paramsMap.put(PSIZE, 10);
        paramsMap.put(TYPE, 1);
        Bundle bundle = getArguments();
        if (bundle != null) {
            String filterStr = bundle.getString(FILTERS);
            if (filterStr != null && !filterStr.equals("")) {
                JSONArray jsonArray = JSON.parseArray(filterStr);
                for (int i = 0, length = jsonArray.size(); i < length; i++) {
                    filtersList.add(jsonArray.getJSONObject(i).toJSONString());
                }
                paramsMap.put(FILTERS, filtersList);
            }
            cate = bundle.getInt(CATE, -1);
            if (cate != -1) {
                paramsMap.put(CATE, cate);
            }
            int brand = bundle.getInt(BRAND, -1);
            if (brand != -1) {
                paramsMap.put(BRAND, brand);
            }
        }
        handleRequest(paramsMap);
    }

    private void handleRequest(WeakHashMap<String, Object> paramsMap) {
        SearchRequestHandler.requestData(paramsMap);
    }

    private void resetPage() {
        curPage = 1;
        paramsMap.put(PAGE, curPage);
        isLast = false;
    }

    private void resetText(int type) {
        switch (type) {
            case 1: {
                synthesizeTv.setText("综合");
                synthesizeCheckNone.setChecked(true);
            }
            break;
            case 2: {
                priceTv.setText("价格");
                priceCheckNone.setChecked(true);
            }
            break;
            case 3: {
                synthesizeTv.setText("综合");
                priceTv.setText("价格");
                synthesizeCheckNone.setChecked(true);
                priceCheckNone.setChecked(true);
            }
            break;
        }
    }

    PopupWindow synthesizeMenu;//综合选项菜单
    PopupWindow priceMenu;//价格排序选项菜单
    PopupWindow filterMenu;//筛选价格选项菜单

    RadioGroup synthesizeGroup;
    RadioGroup priceGroup;
    RadioButton synthesizeCheckNone;
    RadioButton priceCheckNone;

    EditText minPriceEditText;
    EditText maxPriceEditText;

    private int price1 = -1;
    private int price2 = -1;

    RecyclerView filterChooseRV;
    SearchFilterAdapter filterAdapter;

    private Resources resources;

    private void initView(View rootView) {
        resources = _mActivity.getResources();
        navigationLayout.setNavigationOnClickListener((View v) -> {
            synthesizeMenu.dismiss();
            priceMenu.dismiss();
            filterMenu.dismiss();
            pop();
        });
        keyWordEditText.addTextChangedListener(this);
        refreshLayout.setEnableRefresh(false);
        refreshLayout.setOnLoadMoreListener(this);
        loadMoreRun = () ->

        {
            //请求下一页数据
            if (!isLast) {
                paramsMap.put(PAGE, curPage + 1);
                SearchRequestHandler.requestPage(paramsMap);
            } else {
                Toast.makeText(getActivity(), "没有更多数据了", Toast.LENGTH_SHORT).show();
            }
            refreshLayout.finishLoadMore();
        }

        ;
        salesSortRun = () ->

        {
            resetPage();
            paramsMap.put(SORT, sort.desc);
            paramsMap.put(ORDER, order.salesReal);
            handleRequest(paramsMap);
        }

        ;
        View synthesizeContentView = LayoutInflater.from(rootView.getContext())
                .inflate(R.layout.layout_popup_synthesize, null);
        synthesizeMenu = new

                PopupWindow(synthesizeContentView,
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);

        View bgView = synthesizeContentView.findViewById(R.id.view_bg_synthesize);
        bgView.setOnClickListener(this);
        synthesizeGroup = synthesizeContentView.findViewById(R.id.radio_group_synthesize);
        synthesizeCheckNone = synthesizeContentView.findViewById(R.id.check_none);
        synthesizeGroup.setOnCheckedChangeListener((RadioGroup group, int checkedId) -> {
            resetText(2);
            switch (checkedId) {
                case R.id.rb_synthesize: {
                    paramsMap.put(ORDER, order.id);
                    paramsMap.put(SORT, sort.desc);
                    resetPage();
                    handleRequest(paramsMap);
                    synthesizeTv.setText("综合");
                    synthesizeMenu.dismiss();
                }
                break;
                case R.id.rb_new_product_first: {
                    paramsMap.put(ORDER, order.createTime);
                    paramsMap.put(SORT, sort.desc);
                    resetPage();
                    handleRequest(paramsMap);
                    synthesizeTv.setText("新品优先");
                    synthesizeMenu.dismiss();
                }
                break;
                case R.id.rb_comments: { //评论数从高到低
                    paramsMap.put(ORDER, order.comment);
                    paramsMap.put(SORT, sort.desc);
                    resetPage();
                    handleRequest(paramsMap);
                    synthesizeTv.setText("评论数从高到低");
                    synthesizeMenu.dismiss();
                }
                break;
            }

        });
        synthesizeMenu.setAnimationStyle(R.style.popupWindow_anim_style);

        View priceContentView = LayoutInflater.from(rootView.getContext())
                .inflate(R.layout.layout_popup_price, null);
        View priceBgView = priceContentView.findViewById(R.id.view_bg_price);
        priceBgView.setOnClickListener(this);
        priceGroup = priceContentView.findViewById(R.id.radio_group_price);
        priceCheckNone = priceContentView.findViewById(R.id.price_check_none);
        priceGroup.setOnCheckedChangeListener((RadioGroup group, int checkedId) -> {
            resetText(1);

            switch (checkedId) {
                case R.id.rb_price_high_to_low: {
                    paramsMap.put(ORDER, order.memberPrice);
                    paramsMap.put(SORT, sort.desc);
                    resetPage();
                    handleRequest(paramsMap);
                    priceTv.setText("价格从高到低");
                    priceMenu.dismiss();
                }
                break;
                case R.id.rb_price_low_to_high: {
                    paramsMap.put(ORDER, order.memberPrice);
                    paramsMap.put(SORT, sort.asc);
                    resetPage();
                    handleRequest(paramsMap);
                    priceTv.setText("价格从低到高");
                    priceMenu.dismiss();
                }
                break;

            }
        });
        priceMenu = new PopupWindow(priceContentView, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        priceMenu.setAnimationStyle(R.style.popupWindow_anim_style);
        View filterContentView = LayoutInflater.from(rootView.getContext())
                .inflate(R.layout.layout_popup_filter, null);
        minPriceEditText = filterContentView.findViewById(R.id.et_min_price);
        minPriceEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                price1 = getPriceFromEdit(s);
            }
        });
        maxPriceEditText = filterContentView.findViewById(R.id.et_max_price);
        maxPriceEditText.addTextChangedListener(new
                                                        TextWatcher() {
                                                            @Override
                                                            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                                                            }

                                                            @Override
                                                            public void onTextChanged(CharSequence s, int start, int before, int count) {

                                                            }

                                                            @Override
                                                            public void afterTextChanged(Editable s) {
                                                                price2 = getPriceFromEdit(s);
                                                            }
                                                        });
        filterChooseRV = filterContentView.findViewById(R.id.rv_filter);
        filterChooseRV.setLayoutManager(
                new

                        LinearLayoutManager(getContext(),

                        LinearLayoutManager.VERTICAL,
                        false));
        filterAdapter = new

                SearchFilterAdapter(R.layout.item_search_filter);
        filterAdapter.setOnItemChildClickListener(this);
        filterChooseRV.setAdapter(filterAdapter);
        filterMenu = new

                PopupWindow(filterContentView,
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        filterMenu.setFocusable(true);
        View filterBgView = filterContentView.findViewById(R.id.view_bg_filter);
        filterBgView.setOnClickListener(this);
        filterContentView.findViewById(R.id.btn_reset_filter).

                setOnClickListener(this);
        filterContentView.findViewById(R.id.btn_confirm_filter).

                setOnClickListener(this);

        searchRV.setLayoutManager(new

                LinearLayoutManager(getContext(),

                LinearLayoutManager.VERTICAL, false));
        adapter = new

                SearchBeanAdapter(R.layout.item_search_bean);
        adapter.setOnItemClickListener(this);
        searchRV.setAdapter(adapter);
    }

    private int getPriceFromEdit(Editable editable) {
        if (editable.length() > 0) {
            return Integer.valueOf(editable.toString());
        }
        return -1;
    }

    @Override
    public boolean onBackPressedSupport() {
        if (synthesizeMenu.isShowing()) {
            synthesizeMenu.dismiss();
        } else if (priceMenu.isShowing()) {
            priceMenu.dismiss();
        } else if (filterMenu.isShowing()) {
            filterMenu.dismiss();
        } else {
            pop();
        }
        return true;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.view_bg_synthesize: {
                synthesizeMenu.dismiss();
            }
            break;
            case R.id.view_bg_price: {
                priceMenu.dismiss();
            }
            break;
            case R.id.view_bg_filter: {
                filterMenu.dismiss();
            }
            break;
            case R.id.btn_confirm_filter: {
                paramsMap.put(FILTERS, filtersList);
                resetPage();
                setMinMaxPriceParams(paramsMap, price1, price2);
                SearchRequestHandler.requestData(paramsMap);
                filterMenu.dismiss();
                hideSoftInput();
            }
            break;
            case R.id.btn_reset_filter: {
                price1 = -1;
                price2 = -1;
                filtersList.clear();
                paramsMap.clear();
                paramsMap.put(PSIZE, 10);
                paramsMap.put(TYPE, 1);
                resetPage();
                paramsMap.put(CATE, cate);
                SearchRequestHandler.requestData(paramsMap);
                filterMenu.dismiss();
                hideSoftInput();
                minPriceEditText.setText("");
                maxPriceEditText.setText("");
                filterAdapter.setNewData(simpleFilterList);
            }
            break;
        }
    }

    private void setTextState(int pos) {
        switch (pos) {
            case 0: {
                imgVs[0].setImageDrawable(resources.getDrawable(R.drawable.ic_triangle_down_green));

                imgVs[1].setImageDrawable(resources.getDrawable(R.drawable.ic_up_down_gray));
                imgVs[2].setImageDrawable(resources.getDrawable(R.drawable.ic_filter_gray));
            }
            break;
            case 1: {
                imgVs[0].setImageDrawable(resources.getDrawable(R.drawable.ic_triangle_down_gray));
                imgVs[1].setImageDrawable(resources.getDrawable(R.drawable.ic_up_down_gray));
                imgVs[2].setImageDrawable(resources.getDrawable(R.drawable.ic_filter_gray));
            }
            break;
            case 2: {
                imgVs[1].setImageDrawable(resources.getDrawable(R.drawable.ic_up_down_green));

                imgVs[0].setImageDrawable(resources.getDrawable(R.drawable.ic_triangle_down_gray));
                imgVs[2].setImageDrawable(resources.getDrawable(R.drawable.ic_filter_gray));
            }
            break;
            case 3: {
                imgVs[2].setImageDrawable(resources.getDrawable(R.drawable.ic_filter_green));

                imgVs[0].setImageDrawable(resources.getDrawable(R.drawable.ic_triangle_down_gray));
                imgVs[1].setImageDrawable(resources.getDrawable(R.drawable.ic_up_down_gray));
            }
            break;
        }
        for (int i = 0; i < 4; i++) {
            if (i != pos) {
                filterTvs[i].setTextColor(Color.BLACK);
            }
        }
        filterTvs[pos].setTextColor(resources.getColor(R.color.green_dark));
    }

    private void setMinMaxPriceParams(WeakHashMap<String, Object> params, int price1, int price2) {
        if (price1 >= 0 && price2 >= 0 && price1 != price2) {
            int minPrice = Math.min(price1, price2);
            int maxPrice = Math.max(price1, price2);
            params.put(MIN_PRICE, minPrice);
            params.put(MAX_PRICE, maxPrice);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        EventBus.getDefault().unregister(this);
        paramsMap.clear();
        paramsMap = null;
        filtersList.clear();
        filtersList = null;
        if (allFilterList != null) {
            allFilterList.clear();
            allFilterList = null;
        }
        if (simpleFilterList != null) {
            simpleFilterList.clear();
            simpleFilterList = null;
        }
        filterMenu = null;
        priceMenu = null;
        synthesizeMenu = null;

    }

    @BindView(R.id.layout_no_data_tip)
    LinearLayout noDataTipLayout;

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onSearchResult(SearchResultEvent event) {
        if (!event.isNoResult()) {
            adapter.replaceData(event.getSearchBeanList());
            noDataTipLayout.setVisibility(View.GONE);
        } else {
            adapter.replaceData(new ArrayList<SearchBean>());
            noDataTipLayout.setVisibility(View.VISIBLE);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onSearchPage(SearchPageEvent event) {
        if (!event.isNoResult()) {
            adapter.addData(event.getSearchBeanList());
            if (adapter.getData().size() == event.getTotal()) {
                isLast = true;
            }
            curPage++;
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onGetFilters(FilterGotEvent event) {
        allFilterList = event.getFilterBeanList();
        simpleFilterList = getSimpleFilterList(allFilterList);
        ArrayList<SearchFilterBean> adapterList = new ArrayList<>(simpleFilterList);
        filterAdapter.setNewData(adapterList);
    }

    private ArrayList<SearchFilterBean> getSimpleFilterList(ArrayList<SearchFilterBean> sourceList) {
        ArrayList<SearchFilterBean> goalList = new ArrayList<>();
        for (int i = 0, iLength = sourceList.size(); i < iLength; i++) {
            SearchFilterBean sourceBean = sourceList.get(i);
            SearchFilterBean bean = new SearchFilterBean();
            bean.setShowTextAll(sourceBean.isShowTextAll());
            bean.setTitle(sourceBean.getTitle());
            ArrayList<SearchFilterItemBean> itemList = new ArrayList<>();
            for (int j = 0; j < Math.min(3, sourceBean.getItemList().size()); j++) {
                itemList.add(sourceBean.getItemList().get(j));
            }
            bean.setItemList(itemList);
            goalList.add(bean);
        }
        return goalList;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onItemFilterCheckChange(ItemFilterCheckChangeEvent event) {
        for (int i = 0, length = allFilterList.size(); i < length; i++) {
            if (allFilterList.get(i).getTitle().equals(event.getTitle())) {
                ArrayList<SearchFilterItemBean> itemList = allFilterList.get(i).getItemList();
                for (int j = 0, jLength = itemList.size(); j < jLength; j++) {
                    if (itemList.get(j).getValue() == event.getBean().getValue()) {
                        itemList.get(j).setCurrent(event.isChecked());
                        break;
                    }
                }
                break;
            }
        }

        for (int i = 0, length = simpleFilterList.size(); i < length; i++) {
            if (simpleFilterList.get(i).getTitle().equals(event.getTitle())) {
                ArrayList<SearchFilterItemBean> itemList = simpleFilterList.get(i).getItemList();
                for (int j = 0, jLength = itemList.size(); j < jLength; j++) {
                    if (itemList.get(j).getValue() == event.getBean().getValue()) {
                        itemList.get(j).setCurrent(event.isChecked());
                        break;
                    }
                }
                break;
            }
        }
        String filterStr = createFilterStr(event.getBean().getValue(), event.getBean().getKey());
        if (event.isChecked()) {
            filtersList.add(filterStr);
        } else {
            filtersList.remove(filterStr);
        }
    }

    private String createFilterStr(int value, int key) {
        return "{\"value\":\"" + value + "\",\"key\":\"" + key + "\"}";
    }


    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        SearchBean bean = (SearchBean) adapter.getData().get(position);
        GoodsDetailFragment detailDelegate = new GoodsDetailFragment().withId(bean.getId());
        start(detailDelegate);
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        refreshLayout.getLayout().postDelayed(loadMoreRun, 200);
    }

    //*******************************************************************************
    // TextWatcher
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        boolean noWords = s.length() == 0;
        editDeleteImg.setVisibility(noWords ? View.GONE : View.VISIBLE);
        if (noWords) {
            paramsMap.put(KEY_WORDS, "");
            resetPage();
            handleRequest(paramsMap);
        }
    }
    //*******************************************************************************

    @Override
    public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
        //替换数据
        ArrayList<SearchFilterBean> oldList = (ArrayList<SearchFilterBean>) adapter.getData();
        ArrayList<SearchFilterBean> newList = new ArrayList<>(oldList);

        if (oldList.get(position).getItemList().size()
                == allFilterList.get(position).getItemList().size()) {
            newList.remove(position);
            SearchFilterBean bean = SearchFilterBean.copy(simpleFilterList.get(position));
            bean.setShowingAll(false);
            newList.add(position, bean);
        } else {
            newList.remove(position);
            SearchFilterBean bean = SearchFilterBean.copy(allFilterList.get(position));
            bean.setShowingAll(true);
            newList.add(position, bean);
        }
        DiffUtil.DiffResult diffResult =
                DiffUtil.calculateDiff(new FilterItemDiffUtil(oldList, newList), true);
        diffResult.dispatchUpdatesTo(filterAdapter);
        filterAdapter.setNewData(newList);
    }


}
